package thread;

public class YieldTest extends Thread{
    public YieldTest(String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(getName()+"  "+i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (i==5){
                Thread.yield();
            }
        }
    }

    public static  void main(String[] args){
        YieldTest yieldTest1 = new YieldTest("高级");
        yieldTest1.setPriority(Thread.MAX_PRIORITY);
        yieldTest1.start();
        YieldTest yieldTest2 = new YieldTest("低级");
        yieldTest2.setPriority(Thread.MIN_PRIORITY);
        yieldTest2.start();

    }
}
